<template>
	<div class="export-dialog-view" v-loading="pageLoading">
	  <div class="export-dialog">
		<div class="left-lay">
		  <div class="split-title">{{ title }}</div>
		  <div class="left-line">
			<div class="line-title">
			  {{ $t("message.bhView.leftComponents.device") }}
			</div>
			<div class="line-value">{{ $store.state.plantName }}</div>
		  </div>
  
		  <div class="left-line">
			<div class="line-title">
			  {{ $t("message.bhView.leftComponents.object") }}
			</div>
			<div class="line-value">
			  {{
				$store.state.macType == 1
				  ? $t("message.bhView.leftComponents.machine")
				  : $t("message.bhView.leftComponents.piping")
			  }}
			</div>
		  </div>
  
		  <div class="left-line">
			<div class="line-title">
			  {{ $t("message.reportFrom.exportDialog.title_c") }}
			</div>
			<div class="line-value">{{ fileTypeStr }}</div>
		  </div>
		  <div class="left-draw" id="left-draw"></div>
		</div>
  
		<div class="tip-lay"></div>
  
		<div class="right-lay">
		  <div class="split-title text-right">
			<i class="el-icon-close" @click="CloseExprotDiloag"></i>
		  </div>
		  <div class="split-title">
			{{ $t("message.reportFrom.exportDialog.title_l") }}
		  </div>
  
		  <div class="right-line">
			<div class="line-title">浸食度・余寿命</div>
			<div class="line-content zong" style="padding-left:14px;">
			  <el-checkbox v-model="LongTerm" style="margin-right: 48px;">長期</el-checkbox>
			  <el-checkbox v-model="ShortTerm" style="margin-right: 48px;">短期</el-checkbox>
			  <el-checkbox v-model="LSTerm">LS</el-checkbox>
			</div>
		  </div>

		  <div class="right-line">
			<div class="line-title">出力形式</div>
			<div class="line-content" style="padding-left:15px;">
				<el-radio-group v-model="OutputFormat">
				<el-radio :label="'腐食系'">腐食系</el-radio> 
				<el-radio :label="'測定部位'" style="margin-right: 30px;">測定部位</el-radio>
				<el-radio :label="'サイズ'">サイズ</el-radio>
				</el-radio-group>
			</div>
		  </div>

		  <div class="right-line">
          <div class="line-content" style="padding-left:180px;">
            <el-select v-model="ComBoxVal" placeholder=" " class="ipt picker">
              <el-option v-for="(item, index) in ComBoxValList" :key="index" :label="item.label" :value="item.key">
              </el-option>
            </el-select>
          </div>
        </div>
		</div>
  

		<footer class="footer-view">
		  <div>
			<div class="line-title" style="width: 100%">
			  {{ $t("message.reportFrom.exportDialog.tip") }}
			</div>
		  </div>
		  <div>
			<el-button @click="CloseExprotDiloag">Cancel</el-button>
			<el-button type="primary" @click="onExportClick">OK</el-button>
		  </div>
		</footer>
	  </div>
	</div>
  </template>
  
<script>
import { ExEvaluationGraphExcel, 
	getExEvaluationGraphComBox
} from "@/api/api";

export default {
  props: ["title", "fileTypeStr", "selectMacData", "fileRadio"],
  name: "D_C_Export",
  data() {
    return {
	  OutputFormat: '腐食系', //出力形式
      LongTerm: true, //腐食系
	  ShortTerm: true, //短期
	  LSTerm: true, //LS
	  ComBoxValList: [], 
      ComBoxVal: "", 
      pageLoading: false,
    };
  },

  methods: {

    async onExportClick() {
      this.pageLoading = true;
      const pdfList = [];
      let code = this.selectMacData.map(item => parseInt(item.code));
        const dataJson = {
          PltCode: this.$store.state.pltCode,
          Code: code,
		  OutFormat: this.OutputFormat,
		  LongTerm: this.LongTerm ? "長期" : "",
		  ShortTerm: this.ShortTerm ? "短期" : "",
	      LSTerm: this.LSTerm ? "LS" : "",
		  ComBoxVal: this.ComBoxVal
        };
          const res = await ExEvaluationGraphExcel(dataJson);
          this.pageLoading = false;

			if (res.data.code == -310) {
				this.$message.info(res.data.msg);
				return
			}  else if (res.data.code != 0) {
				this.$alert(res.data.msg, '', {
					confirmButtonText: 'OK',
					type: 'warning',
					callback: action => {
					}
				})
				return
			} else if (res.data.code == 0) {
				window.open(res.data.data);
			}
			this.$emit("CloseExprotDiloag");
			return

			
		},

    CloseExprotDiloag() {
      this.$emit("CloseExprotDiloag");
    },

	async getExEvaluationGraphComBoxApi() {
      try {
        let res = await getExEvaluationGraphComBox();
        if (res.data.code === 0) {
          let data = res.data.data;
          this.ComBoxValList = [
            { label: data[0].corrosionRate, key: data[0].corrosionRate },
            { label: data[0].remainingLife, key: data[0].remainingLife }
          ];
          this.ComBoxVal = data[0].corrosionRate;
        }
      } catch (error) {
        console.error("Error fetching combobox values:", error);
      }
    }
  },
  mounted() {
		this.getExEvaluationGraphComBoxApi();

	},
};
</script>
<style lang="scss" scoped>
.export-dialog-view {
	position: fixed;
	width: 100%;
	height: 100%;
	left: 0;
	top: 0;
	z-index: 6;
}

.export-dialog {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 800px;
	height: 350px;
	// height: 292px;
	background: #ffffff;
	box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.05),
		0px 9px 28px 0px rgba(0, 0, 0, 0.08),
		0px 6px 16px -8px rgba(0, 0, 0, 0.15);
	display: flex;
	flex-direction: row;
	padding: 0 12px;
}

.left-lay {
	position: relative;
	width: 40%;
	height: 100%;
	// border-right: 1px solid #ccc;
	display: flex;
	flex-direction: column;
	// background-color: blanchedalmond;

	.left-line {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 0px 20px;
		padding-top: 10px;

		.line-title {
			font-size: 14px;
			font-weight: 700;
			color: rgba(0, 0, 0, 0.85);
			line-height: 22px;
		}

		.line-value {
			font-size: 14px;
			font-weight: 400;
			color: #7b7b7b;
			line-height: 22px;
			margin-left: 10px;
		}
	}

	.left-draw {
		position: absolute;
		top: 100vh;
		width: 750px;
		height: 611px;
		// flex-grow: 1;
		// flex-shrink: 1;
		background-color: bisque;
	}
}

.tip-lay {
	background: red;
	width: 7px;
	border-radius: 4px;
	background: #ccc;
	margin-top: 46px;
	margin: 46px 15px 85px 15px;
}

.right-lay {
	position: relative;
	width: 70%;
	height: 100%;
	display: flex;
	flex-direction: column;

	.el-icon-close {
		font-size: 16px;
		cursor: pointer;
		width: 46px;
		height: 45px;
		line-height: 45px;
	}

	.right-block-container {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.text-right {
		padding: 0 !important;
		text-align: right;
	}

	.right-line {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 0px 12px;
		padding-top: 17px;

		.line-title {
			font-size: 14px;
			font-weight: 700;
			color: rgba(0, 0, 0, 0.85);
			line-height: 22px;
			text-align: left;
			margin-right: 10px;
			width: 110px;
		}

		.line-content {
			flex-grow: 1;
			flex-shrink: 1;
			display: flex;
			flex-direction: row;
			align-items: center;
		}

		.ipt {
			//     width: 368px;
			width: 100%;
			height: 32px;

			::v-deep .el-input__inner {
				width: 100%;
				height: 32px;
			}

			::v-deep .el-input__inner:focus {
				border: 1px solid #dcdfe6;
			}

			::v-deep .el-input__icon {
				line-height: 32px;
				color: #909399;
			}

			::v-deep .el-input__suffix {
				width: 32px;
				right: 0;
				background: #dee0e3;
			}
		}

		.picker {
			width: 130px;
			margin: 0px 10px;

			::v-deep .el-input__inner {
				width: 130px;
			}

			::v-deep .el-input__suffix {
				background: transparent;
			}
		}

		.orange {
			::v-deep .el-input__inner {
				// width: 130px;
				background-color: #FFDEACFF;
			}
		}

		.divider {
			width: 100%;
			height: 1px;
			background-color: #f0f0f0;
		}
	}

	.right-line.bottom-border {
		padding-bottom: 10px;
		// border-bottom: 1px solid #f0f0f0;
	}

	.flex-row {
		flex-direction: row;
	}

	.flex-column {
		flex-direction: column;
	}
}

.split-title {
	width: 100%;
	font-size: 16px;
	font-weight: 700;
	color: rgba(0, 0, 0, 0.85);
	line-height: 22px;
	padding: 12px 12px;
	border-bottom: 1px solid #f0f0f0;
}

.footer-view {
	width: calc(100% - 30px);
	box-sizing: border-box;
	position: absolute;
	z-index: 10;
	bottom: 16px;
	// padding: 0 15px;
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	// background-color: red;
	padding-top: 17px;
	border-top: 1px solid #f0f0f0;
	font-size: 16px;
	font-weight: 700;

	button {
		width: 82px !important;
		height: 32px;
		// background: #ffffff;
		// border: 1px solid #d9d9d9;
		margin-left: 12px;
		border-radius: 4px;
		font-size: 14px;
		font-weight: 500;
		line-height: 0;
	}

	button:nth-child(2) {
		// background: #106ebe;
		// color: #fff;
	}
}

.p0 {
	padding: 12px 0;
}

.el-radio {
	width: 70px;
}

.zong .el-radio-group {
	display: flex;
	flex-direction: column;

	.el-radio {
		margin-top: 12px;
	}
}
</style>
